''' <summary>
''' Applicaiton Helper Class
''' </summary>
''' <remarks></remarks>
Public NotInheritable Class ApplicationHelper

  Private Const STR_TempASPFiles As String = "\Temporary ASP.NET Files\"

  ''' <summary>
  ''' Checks to see if the current applciation is ASP.NET
  ''' </summary>
  ''' <returns>True if running ASP.NET</returns>
  ''' <remarks></remarks>
  Public Shared Function IsAspNet() As Boolean
    If Not String.IsNullOrEmpty(System.AppDomain.CurrentDomain.DynamicDirectory) Then
      Return System.AppDomain.CurrentDomain.DynamicDirectory.Contains(STR_TempASPFiles)
    Else
      Return False
    End If
  End Function

  ''' <summary>
  ''' Gets the calling assembly name.
  ''' </summary>
  ''' <returns>Assembly name.</returns>
  ''' <remarks></remarks>
  Public Shared Function CurrentAssemblyName() As String
    Return System.Reflection.Assembly.GetEntryAssembly.GetName.Name
  End Function

  ''' <summary>
  ''' Loads a list of the running assembly referenced assemblies.
  ''' </summary>
  ''' <returns></returns>
  ''' <remarks></remarks>
  Public Shared Function CurrentAssemblyReferencedAssemblies() As System.Collections.ObjectModel.ReadOnlyCollection(Of String)

    Dim referencedAssemblies As New System.Collections.Generic.List(Of String)

    For Each assembly As System.Reflection.AssemblyName In System.Reflection.Assembly.GetEntryAssembly.GetReferencedAssemblies

      referencedAssemblies.Add(assembly.ToString)

    Next

    Return New System.Collections.ObjectModel.ReadOnlyCollection(Of String)(referencedAssemblies)

  End Function

  ''' <summary>
  ''' Verifys the current user on the current thread is an administrator.
  ''' </summary>
  ''' <returns><see cref="Boolean">True</see> if current user is administrator.</returns>
  ''' <remarks></remarks>
  Public Shared Function CurrentUserIsAdministrator() As Boolean
    Dim currentDomain As AppDomain = System.Threading.Thread.GetDomain()

    currentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal)
    Dim currentPrincipal As System.Security.Principal.WindowsPrincipal = CType(System.Threading.Thread.CurrentPrincipal, System.Security.Principal.WindowsPrincipal)

    Return currentPrincipal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)

  End Function

  Private Sub New()
  End Sub

End Class

